	capture mkdir "shares"
	scalar year_up=2011
	
	// groups with 2 categories
	
	
	local var "group_gender group_urban group_employed group_knowledge group_gov_trust group_interest group_language"
	foreach x of local var{ 
	use data3.dta, clear
	
	matrix Nobs=J(2,1,.)
	
	forvalues i=1(1)2{
	sum  `x' if `x'==(`i')  
	matrix Nobs[`i',1]=r(N)
	}
	
	svmat Nobs, names(Nobs)
	
	keep if !missing(Nobs)

	gen group=_n
	gen variable="`x'"
	egen Nobs_total=sum(Nobs1)
	gen share=Nobs1/Nobs_total
	keep Nobs1 share group variable
	
	saveold ./shares/Nobs_`x'_all.dta, replace
	}
	
	
	// groups with 3 categories
	
	local var "group_educ group_age  group_orientation group_religion group_orientation_alt group_participation group_party group_income"
	foreach x of local var{  
	use data3.dta, clear
	
	matrix Nobs=J(3,1,.)
	
	forvalues i=1(1)3{
	sum  `x' if `x'==(`i')  
	matrix Nobs[`i',1]=r(N)
	}
	
	svmat Nobs, names(Nobs)
	
	keep if !missing(Nobs)

	gen group=_n
	gen variable="`x'"
	egen Nobs_total=sum(Nobs1)
	gen share=Nobs1/Nobs_total
	keep Nobs1 share group variable
	
	saveold ./shares/Nobs_`x'_all.dta, replace
	}
	
	// groups with 5 categories
	
	local var "group_party_identification"
	foreach x of local var{  
	use data3.dta, clear
	
	matrix Nobs=J(5,1,.)
	
	forvalues i=1(1)5{
	sum  `x' if `x'==(`i')  
	matrix Nobs[(`i'),1]=r(N)
	}
	
	svmat Nobs, names(Nobs)
	
	keep if !missing(Nobs)

	gen group=_n
	gen variable="`x'"
	egen Nobs_total=sum(Nobs1)
	gen share=Nobs1/Nobs_total
	keep Nobs1 share group variable
	
	saveold ./shares/Nobs_`x'_all.dta, replace
	}

	// append all groups
	
	
	use ./shares/Nobs_group_party_identification_all.dta, clear

	capture gen variable="group_party_identification"
	local count_var=1
	gen variable_num=1
	gen var_sort=1

	
	local var "group_orientation group_interest group_knowledge group_gov_trust group_age group_educ group_employed group_income group_language group_religion group_urban"
	foreach x of local var{  
	local count_var=`count_var' +1
	append using ./shares/Nobs_`x'_all.dta
	replace variable="`x'" if  variable==""
	replace variable_num=`count_var' if  variable_num==.
	local new = _N + 1 // add one observation for labeling of group description
 	replace var_sort=`count_var' if var_sort==.

	}
	

	
	gsort variable_num  -group  // generate index for y-axis of plot
	gen id=_n
	
	// labeling
	
	

	gen group_description=""
	replace group_description="Ideology" if variable=="group_orientation"
	replace group_description="Political interest" if variable=="group_interest"
	replace group_description="Political knowledge" if variable=="group_knowledge"
	replace group_description="Trust in government" if variable=="group_gov_trust"
	replace group_description="Age" if variable=="group_age"
	replace group_description="Education" if variable=="group_educ"
	replace group_description="Employment status" if variable=="group_employed"
	replace group_description="Language" if variable=="group_language"
	replace group_description="Religion" if variable=="group_religion"
	replace group_description="Residence" if variable=="group_urban"
	replace group_description="Income" if variable=="group_income"
	replace group_description="Party identification" if variable=="group_party_identification"

	gen group_member_descr=""
	replace group_member_descr="Left" if variable=="group_orientation" & group==1
	replace group_member_descr="Center" if variable=="group_orientation" & group==2
	replace group_member_descr="Right" if variable=="group_orientation" & group==3

	replace group_member_descr="Interested" if variable=="group_interest" & group==1
	replace group_member_descr="Not interested" if variable=="group_interest" & group==2

	replace group_member_descr="Trust" if variable=="group_gov_trust" & group==1
	replace group_member_descr="No trust" if variable=="group_gov_trust" & group==2
	
	replace group_member_descr="18-39" if variable=="group_age" & group==1
	replace group_member_descr="40-65" if variable=="group_age" & group==2
	replace group_member_descr=">65" if variable=="group_age" & group==3

	replace group_member_descr="Low" if variable=="group_educ" & group==1
	replace group_member_descr="Middle" if variable=="group_educ" & group==2
	replace group_member_descr="High" if variable=="group_educ" & group==3

	replace group_member_descr="Employed" if variable=="group_employed" & group==1
	replace group_member_descr="Unemployed" if variable=="group_employed" & group==2

	replace group_member_descr="German" if variable=="group_language" & group==1
	replace group_member_descr="French/Italian" if variable=="group_language" & group==2

	replace group_member_descr="Other" if variable=="group_religion" & group==3
	replace group_member_descr="Protestant" if variable=="group_religion" & group==1
	replace group_member_descr="Catholic" if variable=="group_religion" & group==2
	
	replace group_member_descr="Urban" if variable=="group_urban" & group==1
	replace group_member_descr="Rural" if variable=="group_urban" & group==2
	
	replace group_member_descr="Low" if variable=="group_income" & group==1
	replace group_member_descr="Middle" if variable=="group_income" & group==2
	replace group_member_descr="High" if variable=="group_income" & group==3
	
	replace group_member_descr="Other" if variable=="group_party_identification" & group==5
	replace group_member_descr="Leftist" if variable=="group_party_identification" & group==1
	replace group_member_descr="CVP" if variable=="group_party_identification" & group==2
	replace group_member_descr="FDP" if variable=="group_party_identification" & group==3
	replace group_member_descr="Rightist" if variable=="group_party_identification" & group==4
	//replace group_member_descr="Leftist parties" if variable=="group_party_identification" & group==6
	//replace group_member_descr="Rightist parties" if variable=="group_party_identification" & group==7

	replace group_member_descr="Political knowledge:" if variable=="group_knowledge" & group==0	
	replace group_member_descr="Low" if variable=="group_knowledge" & group==1
	replace group_member_descr="High" if variable=="group_knowledge" & group==2
	
	
	bysort group_description: gen indi_group_descr=_n
	sort group_member_descr group_description  
	bysort group_member_descr group_description: gen indi_group_member_descr=_n 
	
	sort variable_num
	
	saveold ./shares/Nobs_all.dta, replace version(12)